/*
 * @Author: 李琪 liqi@lark2game.com
 * @Date: 2025-04-15 20:27:16
 * @LastEditors: 李琪 liqi@lark2game.com
 * @LastEditTime: 2025-04-15 20:41:44
 * @FilePath: /cocosBehavior/assets/Script/Base/BTNode.ts
 * @Description: 行为树基类BTNode
 */

import { BTNodeStatus } from "../BTEnum/BTIndex";

const { ccclass, property } = cc._decorator;

@ccclass
export default abstract class BTNode extends cc.Component {
    private _status: BTNodeStatus = BTNodeStatus.Inactive;

    run() {
        if (this._status == BTNodeStatus.Inactive) {
            this.onStart();
        }
        const result = this.onUpdate();
        if (result != BTNodeStatus.RUNNING) {
            this.onEnd();
        }
        return result;
    }

    onStart() {
        this._status = BTNodeStatus.RUNNING;
    }

    onUpdate() {
        return BTNodeStatus.SUCCESS;
    }
    onEnd() {
        this._status = BTNodeStatus.Inactive;
    }
}
